<?php
// $Id$

/**
 * Controller_Admin_Acctproducts 控制器
 */
class Controller_Admin_Acctproducts extends Controller_Abstract
{
	function _format_appendSql()
	{
		if (isset($_SESSION['acct']))
		{
			if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1)
			{
				//为管理
				//$append['']
				$append['admin_id'] = $_SESSION['acct']['id'];
	
			}else
			{
				$append['admin_id'] = $_SESSION['acct']['admin_id'];
				$append['agent_id'] = $_SESSION['acct']['id'];
				//$append['id'] = Acct::_get_have_acctid($_SESSION['acct']['id'], $_SESSION['acct']['admin_id']);
	
			}
		}
		return $append;
	}
	function actionIndex()
	{
		$this->union_table = Acctproduct::meta();
		$agent_list = Acct::_get_arrayinfo();
		$this->_view['agent_list'] = $agent_list;
		$this->lists(parent::_format_appendSql());//array('admin_id'=>-1)为管理
	}
	function actionadd()
	{
		$this->union_table = Acctproduct::meta();
		$handle = new helper_autoinsert($this->union_table);
		$form = new Form_acctproducts_add(url($this->_context->controller_name.'/'.$this->_context->action_name));
		$result = $handle->add($form, 'id',$_GET);
		
		if ($this->_context->isGET())
		{
			//添加 编辑时候 默认所属代理
				if($_SESSION['acct']['acclevel'] == 2 && !isset($_GET['id']))
				{
					$result->element('admin_id')->value = $_SESSION['acct']['admin_id'];
					$result->element('agent_id')->value = $_SESSION['acct']['id'];
				}else if($_SESSION['acct']['acclevel'] == 0 && !isset($_GET['id'])) 
				{
					$result->element('admin_id')->value = $_SESSION['acct']['admin_id'];
					$result->element('agent_id')->value = $_SESSION['acct']['id'];
				}
				
			$this->_view['form'] = $result;
			$this->_viewname = '../form/add';
		}else {
			Syslog::logs('编辑代理产品:'.$_POST['title']);
			return call_user_func_array(array($this,$handle->status),array($result));
		}
	}
	function actiondel()
	{
		Syslog::logs('删除代理产品:'.$this->_context->ids);
		$this->union_table = Acctproduct::meta();
		$this->delete(array_merge($this->_format_appendSql(),array('id'=>$this->_context->ids)));
	}
	
	function actionuserpay()
	{
		
	}
}


